//
//  QBMainVC.m
//  Doctor
//
//  Created by 阳光 on 16/9/7.
//  Copyright © 2016年 阳光. All rights reserved.
//

#import "QBMainVC.h"
#import "QBNavigationController.h"

#import "HomeMainVC.h"
#import "TimeMainHomeVC.h"
#import "PatientMainHomeVC.h"
#import "PaperMainHomeVC.h"
#import "GuideMainHomeVC.h"
#import "SetMainHomeVC.h"
#import "DoctorInfoVC.h"
#import "DoctorHospitalListVC.h"
#import "QBBaseMainVC.h"
#import "LeftMenuView.h"

@interface QBMainVC ()<UIGestureRecognizerDelegate,LeftMenuViewDelegate>

@end

@implementation QBMainVC


- (void)viewDidLoad
{
    [super viewDidLoad];
    
    NSString *vc;
    
    if ([[Util getUserDefaultObjectForKey:@"ShopId"] isEqualToString:@"0"])
    {
        vc=@"DoctorHospitalListVC";
    }
    else
    {
        vc=@"AddTimeListVC";
    }
    
    // 添加子控制器
//    NSArray *classNames=@[@"HomeMainVC",vc, @"PatientMainHomeVC",@"PaperMainHomeVC",@"GuideMainHomeVC",@"SetMainHomeVC",@"DoctorInfoVC"];
    
      NSArray *classNames=@[@"HomeMainVC",vc, @"PatientMainHomeVC",@"PaperMainHomeVC",@"GuideMainHomeVC",@"SetMainHomeVC",@"DoctorInfoVC"];
    //,@"GuideMainHomeVC"
    
    for (NSString *className in classNames){
        UIViewController *vc=(UIViewController *)[NSClassFromString(className)new];
        QBNavigationController *nc=[[QBNavigationController alloc] initWithRootViewController:vc];
//        nc.title=vc.title;
        [self addChildViewController:nc];
    }
    
    // 创建左边MenuView
    LeftMenuView *leftMenuView=[LeftMenuView new];
    leftMenuView.delegate=self;
    [self.view insertSubview:leftMenuView atIndex:0];
    [leftMenuView makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.bottom.mas_equalTo(0);
        make.width.mas_equalTo(APPW*2/3);
    }];
    
}

// LeftMenuViewDelegate
-(void)leftMenuViewButtonClcikFrom:(LeftMenuViewType)fromIndex to:(LeftMenuViewType)toIndex
{
    // 移除旧的控制器view
    QBNavigationController *oldNC=self.childViewControllers[fromIndex];
    [oldNC.view removeFromSuperview];
    
    // 新的控制器view
    QBNavigationController *newNC=self.childViewControllers[toIndex];
    
    if (toIndex==LeftMenuViewTypeIcon)
    {
        newNC=self.childViewControllers[fromIndex];
    }
    // 添加新的控制器view
    [self.view addSubview:newNC.view];
    newNC.view.transform=oldNC.view.transform;
    
    QBBaseMainVC *baseMainVC=[QBBaseMainVC new];
    baseMainVC=newNC.childViewControllers[0];
    [baseMainVC coverClick];
    
}


@end



